package com.youdoneed.community.accounts.web;

import com.youdoneed.community.accounts.entity.Accounttype;
import com.youdoneed.community.accounts.service.AccountTypeService;
import com.youdoneed.community.common.vo.ResultMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 差旅费用类型模块请求控制器。
 *
 * @author shum
 * @date 2017.5.26
 */
@RestController
@RequestMapping(value = "/accountType", method = {RequestMethod.GET, RequestMethod.POST})
@Api(value = "差旅费用类型模块请求控制器", description = "差旅费用类型模块的相关操作")
public class AccountTypeController {

    private static final Logger logger = LoggerFactory.getLogger(AccountTypeController.class);
    @Autowired
    AccountTypeService accountTypeService;

    @RequestMapping(value = "/save", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台保存差旅费用类型", value = "后台保存差旅费用类型")
    public ResultMessage save(Accounttype type) {
        accountTypeService.save(type);
        return ResultMessage.newSuccess("差旅添加成功");
    }

    @RequestMapping(value = "/update", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台更新差旅费用类型", value = "后台更新差旅费用类型")
    public ResultMessage update(Accounttype type) {
        accountTypeService.update(type);
        return ResultMessage.newSuccess("差旅修改成功！");
    }

    @RequestMapping(value = "/delete", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台删除差旅费用类型记录", value = "后台删除差旅费用类型记录")
    public ResultMessage delete(String accountType) {
        accountTypeService.delete(accountType);
        return ResultMessage.newSuccess("差旅删除成功！");
    }

    @RequestMapping(value = "/selectById", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台查询单条差旅费用类型记录", value = "后台查询单条差旅费用类型记录")
    public Accounttype selectById(String id) {
        return accountTypeService.selectById(id);
    }

    @RequestMapping(value = "/query", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "后台查询所有差旅费用类型记录", value = "后台查询所有差旅费用类型记录")
    public ResultMessage queryAllAccountType(Accounttype accounttype, int limit, int offset) {
        List<Accounttype> content = accountTypeService.selectParamPage(accounttype, limit, offset);
        if (null == content) {
            return ResultMessage.newFailure("获取差旅费用类型失败！");
        }
        return ResultMessage.newSuccess("获取差旅费用类型成功").setData(content);
    }
    /*@RequestMapping(value ="/selectPage" ,method = { RequestMethod.GET, RequestMethod.POST })
  	@ApiOperation(notes = "后台分页查询公司开票记录", value = "后台分页查询公司开票记录")
    public List<Accounttype>  selectPage(Accounttype accounttype,String rows,String currentPage) {
  		int newRows = Integer.parseInt(rows);
  		int newCurrentPage = Integer.parseInt(currentPage);
  		return accountTypeService.selectParam_Page(accounttype, newRows, newCurrentPage);
      }*/
}
